﻿package plugin.instances.game
{
    import com.core.*;
    import com.sh.game.util.*;
    import flash.events.*;
    import flash.utils.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import plugin.instances.*;
    import uiresource.instances.ui.*;
    import view.*;
    import view.mornExtends.*;
    import vo.*;

    public class ChangCopyGame extends OldChuangCopyUI implements IInstance
    {
        private var isInit:Boolean = false;
        private var cfgStore:Object;
        private var cfgitem:Object;

        public function ChangCopyGame()
        {
            this.cfgStore = ConfigDictionary.data.storeNew;
            this.cfgitem = ConfigDictionary.data.item;
            list_item.renderHandler = new Handler(this.itemRender);
            list_item2.renderHandler = new Handler(this.buyRender);
            return;
        }// end function

        public function initShow(param1:Object, param2:Dictionary) : void
        {
            var _loc_6:Object = null;
            var _loc_7:int = 0;
            var _loc_8:Object = null;
            txt_desc.text = param1.tips.replace(/#""#/g, "\n");
            var _loc_3:String = "";
            var _loc_4:* = ConfigDictionary.data.monster;
            var _loc_5:* = String(param1.monsters).split("/");
            for each (_loc_6 in _loc_5)
            {
                
                if (_loc_6 != "")
                {
                    if (_loc_3 != "")
                    {
                        _loc_3 = _loc_3 + ("," + _loc_4[_loc_6].name);
                        continue;
                    }
                    _loc_3 = _loc_3 + _loc_4[_loc_6].name;
                }
            }
            if (!this.isInit)
            {
                _loc_7 = 0;
                if (param2)
                {
                    _loc_8 = param2[InstancesPublic.MONSTERNUM];
                    if (_loc_8)
                    {
                        _loc_7 = int(_loc_8.total) - int(_loc_8.kill);
                    }
                }
                txt_mons.text = "";
            }
            txt_boss.text = "该层守卫：<font color=\'" + MColor.Newstr19 + "\'>" + _loc_3 + "</font>";
            this.showItem(param1.show);
            this.isInit = true;
            this.showBuy(param1.buy);
            return;
        }// end function

        public function showBuy(param1:String) : void
        {
            var _loc_2:* = param1.split("#");
            var _loc_3:Array = [];
            while (_loc_2.length > 0)
            {
                
                _loc_3.push({itemid:_loc_2.shift(), storeId:_loc_2.shift()});
            }
            list_item2.array = _loc_3;
            return;
        }// end function

        private function buyRender(param1:Component, param2:int) : void
        {
            var _loc_3:Object = null;
            var _loc_4:Object = null;
            var _loc_5:Label = null;
            if (param2 < list_item2.length)
            {
                _loc_3 = list_item2.array[param2];
                _loc_4 = ConfigDictionary.data.item;
                (param1.getChildByName("box") as FlashItem).data = ItemObject.create(_loc_4[_loc_3.itemid]);
                _loc_5 = param1.getChildByName("txt_buy") as Label;
                _loc_5.isHtml = true;
                _loc_5.text = "<A href=\"event:doBuy\">购买</A>";
                if (_loc_5.hasEventListener(MouseEvent.CLICK))
                {
                    _loc_5.removeEventListener(MouseEvent.CLICK, this.doBuy);
                }
                _loc_5.addEventListener(MouseEvent.CLICK, this.doBuy);
                _loc_5.dataSource = _loc_3;
            }
            return;
        }// end function

        protected function linkHandler(event:TextEvent) : void
        {
            return;
        }// end function

        protected function doBuy(event:MouseEvent) : void
        {
            var _loc_2:* = event.currentTarget.parent.dataSource;
            var _loc_3:* = ItemObject.create(this.cfgitem[_loc_2.itemid]);
            var _loc_4:* = this.cfgStore[_loc_2.storeId];
            DialogMgr.instance.open(AppDialog.SC_BUY, {msg:_loc_4, item:_loc_3});
            return;
        }// end function

        private function showItem(param1:String) : void
        {
            var _loc_2:* = new ItemSplit();
            var _loc_3:* = _loc_2.doSplits(param1, "&", "/", "#");
            list_item.array = _loc_3[0];
            return;
        }// end function

        private function itemRender(param1:Component, param2:int) : void
        {
            if (param2 < list_item.length)
            {
                (param1 as FlashItem).data = list_item.array[param2];
            }
            return;
        }// end function

        public function updateShow(param1:int, param2:Object) : void
        {
            var _loc_3:int = 0;
            switch(param1)
            {
                case InstancesPublic.MONSTERNUM:
                {
                    _loc_3 = int(param2.total) - int(param2.kill);
                    txt_mons.text = "";
                    break;
                }
                case InstancesPublic.TIMECHECKER:
                {
                    txt_time.text = "倒计时：" + TimeDataFormatUtil.getLeftTime(int(param2));
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        public function destroyShow(param1:Dictionary) : void
        {
            this.removeEvent();
            return;
        }// end function

        public function initEvent() : void
        {
            btn_close.clickHandler = new Handler(this.doClose);
            return;
        }// end function

        protected function doLink(event:TextEvent) : void
        {
            return;
        }// end function

        private function doClose() : void
        {
            ModelProxy.change("zone", "exitInstance", null);
            return;
        }// end function

        public function removeEvent() : void
        {
            return;
        }// end function

    }
}
